﻿using ColorLife.Core.FileManager;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;

/// <summary>
/// Summary description for FileService
/// </summary>

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class FileService : System.Web.Services.WebService
{

    private JavaScriptSerializer _serializer;
    
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public JsTreeItem GetTreeData(string path)
    {
        var rootNode = FileManager.Instance.GetJsTreeData(path);
		  
        return rootNode;
    }
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public List<FileItem> LoadAllFileFolder(string path, string searchTxt, string sortOrder, int filter)
    {
        string allowedExtensions = "^.jpg|.gif|.png|.jpeg|.rar|.zip|.swf$";// DalatGreen.Core.Entities.Settings.Setting("file.allowfileext");

        var query = from item in FileManager.Instance.All(path, searchTxt, sortOrder, (FileFilter)filter, allowedExtensions)
                    //  orderby item.LastWriteDate
                    select item;
        //if (query.Count() > 250)
        //    return query.ToList().GetRange(0, 250);
        //return query.ToList();

        return query.ToList();
    }
}